package com.easy.web.utils;


import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: jiaGaoYang
 * Date: 13-12-10
 * Time: 下午12:34
 * To change this template use File | Settings | File Templates.
 */
public class ViewUtils {

	/**
	 * 返回success为true的map对象
	 *
	 * @param result 响应map对象
	 * @return 返回success为true的map对象
	 */
	public static Map<String,Object> mapSuccess(Object result) {
		return mapResult(result, Boolean.TRUE, "200", "");
	}

	/**
	 * 返回success为true的map对象
	 *
	 * @param result,  结果
	 * @param message， 消息
	 * @return 返回success为true的map对象
	 */
	public static Map<String,Object> mapSuccess(Object result, String message) {
		return mapResult(result, Boolean.TRUE, "200", message);
	}

	/**
	 * @param message 消息
	 * @return 返回success为false的map结果
	 */
	public static Map<String,Object> mapFail(String message) {
		return mapResult(null, Boolean.FALSE, "200", message);
	}
	/**
	 * @param message 消息
	 * @param code code
	 * @return 返回success为false的map结果
	 */
	public static Map<String,Object> mapFail(String code, String message) {
		return mapResult(null, Boolean.FALSE, code, message);
	}
	/**
	 * 拼装输出View的MAP对象
	 * @param result 结果
	 * @param success 是否成功
	 * @param code 状态码
	 * @param message 信息
     * @return map
     */
	public static Map<String,Object> mapResult(Object result, boolean success, String code, String message) {
		Map<String,Object> response = new HashMap<>();
		response.put("success", success);
		response.put("code", code);
		response.put("message", message);
		response.put("data", result);
		response.put("date", new Date().getTime());
		return response;
	}
}
